#pragma once
#include "3rdparty/angelscript/include/angelscript.h"


struct script_registration_helper_t
{
	const char* function_name;
	const char* function_group;
	asSFuncPtr function_ptr;

	script_registration_helper_t(){}
	script_registration_helper_t(const char* decl, asSFuncPtr ptr,const char* fgr):function_name(decl),function_ptr(ptr),function_group(fgr){}
};

struct script_manager_t
{
	script_manager_t();
	~script_manager_t();
	static void init();
	static void exit();
	void register_functions();
	void load_scripts(int reinit=1);
	void load_script_file(const char* file_name,string& script);
	static void register_function(const char* decl,asSFuncPtr ptr)
	{
		helper_buf[helper_num++]=script_registration_helper_t(decl,ptr,function_group);
	}

	void execute_script_function(const char* script_function);
	asIScriptContext* get_context();

	static script_registration_helper_t helper_buf[1024];
	static int helper_num;
	asIScriptEngine* script_engine;
	asIScriptContext *global_context[4];
	static const char* function_group;
};


#define _concat_(_a_,_b_) _a_##_b_
#define register_script_fn(_decl_,_fn_)  script_manager_t::register_function(_decl_,asFUNCTION(_fn_))

#define script_fn_registering_begin(__valami__) int fuggveny##__valami__(); static int valtozo##__valami__=fuggveny##__valami__(); static int fuggveny##__valami__(){ script_manager_t::function_group=#__valami__;
#define script_fn_registering_end  return __LINE__;}

extern script_manager_t* SCRIPTMAN;